package com.sun.wanandroid.ui.splash.task

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import com.google.auto.service.AutoService
import com.sun.module_base.theme.black5
import com.sun.module_base.theme.white
import com.sun.module_common.sp.SpUtils
import com.sun.module_network.utils.logd
import com.sun.wanandroid.ui.splash.ISplashComposableTask
import com.sun.wanandroid.ui.splash.SplashViewModel

/**
 *@author:sunc
 *@time :2025/7/25 11:07
 *@desc: 描述 隐私协议
 */

@AutoService(ISplashComposableTask::class)
class PrivacyAgreementComposableTask : ISplashComposableTask {
    override val content: @Composable ((SplashViewModel) -> Unit)
        get() = { PrivacyAgreementScreen(viewModel = it) }

    override val index: Int
        get() = 1
}

@Composable
fun PrivacyAgreementScreen( viewModel: SplashViewModel) {
    var openDialog by remember { mutableStateOf(!SpUtils.isAgree) }
    "PrivacyAgreementScreen$openDialog  ".logd()
    if (openDialog) {
        AlertDialog(
            modifier = Modifier.fillMaxWidth(fraction = 0.9f),
            onDismissRequest = {
                openDialog = false
            }, title = { Text("是否同意隐私协议") }, text = {
                Text(text = "隐私协议")
            }, confirmButton = {
                Button(
                    colors = ButtonDefaults.buttonColors(containerColor = black5),
                    onClick = {
                        SpUtils.isAgree = true
                        openDialog = !SpUtils.isAgree
                    }) {
                    Text("确定", color = white)
                }
            }, dismissButton = {
                Button(
                    onClick = {
                        SpUtils.isAgree = false
                        openDialog = !SpUtils.isAgree
                        viewModel.exitApp()
                    }) {
                    Text("取消", color = white)
                }
            })
    } else {
        viewModel.FindNextTask()
    }
}